﻿using System.ServiceProcess;
using System.Threading;
using SDT.CrawlSystem.Servers;

namespace SDT.Services.UCService
{
    /// <summary>
    /// Written by SinhNT
    /// </summary>
    public partial class UCService : ServiceBase
    {
        private UCContainer container = UCContainer.Instance;

        public UCService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {   
            container.StartAll();
            base.OnStart(args);
        }

        public void Run()
        {
            container.StartAll();
        }

        protected override void OnStop()
        {
            var n = 0;
            while (!container.StopAll() && n < 2)
            {
                n++;
                Thread.Sleep(60000);
            }

            if (n == 2)
                return;
            base.OnStop();
        }
    }
}